package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.model.Notice;
import com.runfast.waimai.dao.model.RunfastAgentApplication;
import com.runfast.waimai.dao.model.RunfastAgentApplicationExample;
import com.runfast.waimai.service.NoticeService;
import com.runfast.waimai.service.RunfastAgentApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RunfastAgentApplicationServiceImpl extends BaseService<RunfastAgentApplication, Integer, RunfastAgentApplicationExample> implements RunfastAgentApplicationService {
    @Autowired
    private NoticeService noticeService;
    public void AgentApplicationToNotice(){
        RunfastAgentApplicationExample example=new RunfastAgentApplicationExample();
        example.createCriteria().andHavereadEqualTo(false);
        List<RunfastAgentApplication> runfastAgentApplicationList=this.mapper.selectByExample(example);
        if(runfastAgentApplicationList.size()>0){
            for(RunfastAgentApplication  runfastAgentApplication:runfastAgentApplicationList){
                Notice notice=new Notice();
                notice.setTitle("代理商加盟："+runfastAgentApplication.getName());
                notice.setDeleted(false);
                notice.setHaveread(false);
                notice.setCreatetime(new Date());
                notice.setOnlyadmin(true);
                String s="<p><strong>意向代理城市</strong>："+runfastAgentApplication.getIntentioncity()
                        +"</p><p><br></p><p><strong>联系人</strong>："+runfastAgentApplication.getName()
                        +"</p><p><br></p><p><strong>联系电话</strong>："+runfastAgentApplication.getMobile()
                        +"</p><p><br></p><p><strong>是否有相关资源或经验的介绍</strong>："+runfastAgentApplication.getIntroduce()+"</p><p><br></p>";
                notice.setContent(s);
                noticeService.insert(notice);
                runfastAgentApplication.setHaveread(true);
                this.mapper.updateByPrimaryKeySelective(runfastAgentApplication);
            }
        }
    }
}